home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / fe1.zip / MAIN.CPP < prev    next >
C/C++ Source or Header  |  1992-02-07  |  2KB  |  99 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include "bmp.h"
  6.  
  7. int match ( FILE *f ) {
  8.  
  9.     char s[10] ;
  10.     int i ;
  11.  
  12.     while ( !feof( f ) ) {
  13.         fscanf( f, "%4s", s ) ;
  14.         if ( !strncmp( s, "0x", 2 ) ) {
  15.             sscanf( &s[2], "%x", &i ) ;
  16.             return i ;
  17.         }
  18.     }
  19.     return 0 ;
  20. }
  21.  
  22. char **readmap ( FILE *f, int w, int h ) {
  23.  
  24.     char **b ;
  25.     int p, i, j, k ;
  26.  
  27.     b = new char * [w] ;
  28.     for ( i = 0 ; i < w ; i++ )
  29.         b[i] = new char [h] ;
  30.     for ( i = 0 ; i < h ; i++ )
  31.         for ( j = 0 ; j < w ; j += 8 ) {
  32.             p = match( f ) ;
  33.             for ( k = j ; k < j + 8 && k < w ; k++ ) {
  34.                 b[k][h - i - 1] = p & 0x80 ? 1 : 0 ;
  35.                 p <<= 1 ;
  36.             }
  37.         }
  38.     return b ;
  39. }
  40.  
  41. main ( int argc, char **argv ) {
  42.  
  43.     editmap *edit ;
  44.     FILE *f ;
  45.     char a, **b = NULL ;
  46.     int w, h ;
  47.  
  48.     if ( argc != 2 && argc != 3 ) {
  49. usage :        puts( "fe <filename> [WIDTHxHEIGHT]\n"
  50.             "WIDTH and HEIGHT must be less tahn 84\n"
  51.             "For example:\n"
  52.             "To edit a new file: FE TEST 32x32\n"
  53.             "To edit an existed file: FE TEST"
  54.         );
  55.         exit( -1 ) ;
  56.     }
  57.  
  58.     if ( argc == 3 ) {
  59.         if ( ( f = fopen( argv[1], "rt" ) ) != NULL )
  60.             goto okfile ;
  61.         sscanf( argv[2], "%dx%d", &w, &h ) ;
  62.  
  63.     } else if ( argc != 2 )
  64.         goto usage ;
  65.     else {
  66.         if ( ( f = fopen( argv[1], "rt" ) ) == NULL )
  67.             goto usage ;
  68. okfile :    fscanf( f, "%*s %*s %*s %*s %*s %*s %d, %d } ;", &w, &h ) ;
  69.         w++; h++;
  70.         b = readmap( f, w, h ) ;
  71.         fclose( f ) ;
  72.     }
  73.     if ( w > 84 || h > 84 || w <= 0 || h <= 0 )
  74.         goto usage ;
  75.  
  76.  
  77.     if ( !msm_init() || !fg_init_all() ) {
  78.         fputs( "Cannot initialize display device", stderr ) ;
  79.         exit( -1 ) ;
  80.     }
  81.     msm_setareax( 0, fg.displaybox[FG_X2] ) ;
  82.     msm_setareay( 0, fg.displaybox[FG_Y2] ) ;
  83.     msm_showcursor() ;
  84.  
  85.     edit = new editmap ( w, h, argv[1] ) ;
  86.     if ( b ) {
  87.         edit->copymap( b ) ;
  88.         delete b ;
  89.     }
  90.     edit->expose() ;
  91.     edit->focus() ;
  92.     delete edit ;
  93.     fg_term() ;
  94.     return 0 ;
  95. }
  96.  
  97. int fg_init_all() { return fg_init_vga12() ; }
  98.  
  99.